<?php
	/*** By Weerachai Nukitram ***/
	/***  http://www.ThaiCreate.Com ***/
include("../connect/connect.php");
include('../function/function.php');

$tABF = $_POST['abf'];
$ExtraAbf = $_POST['ExtraAbf'];
$Extra = $_POST['Extra'];
$AbfA = $_POST['AbfA'];
$AbfC = $_POST['AbfC'];
$AddA = $_POST['AddA'];
$AddC = $_POST['AddC'];
$gValue = $_POST['gValue'];
$rID = $_POST['rID'];
/*
 * รหัสข้อมูล
$tABF = 1
$ExtraAbf = 2
$Extra = 3
$AbfA = 4
$AbfC = 5
$AddA = 6
$AddC = 7


echo "tABF=".$tABF."<br>";
echo "ExtraAbf=".$ExtraAbf."<br>";
echo "Extra=".$Extra."<br>";
echo "AbfA=".$AbfA."<br>";
echo "AbfC=".$AbfC."<br>";
echo "AddA=".$AddA."<br>";
echo "AddC=".$AddC."<br>";
*/
$rQuery = mysql_query("SELECT roomtype.roomtype_id as roomtype,roomtype.roomtype_name as roomtype_name,count(roomtype.roomtype_id) as roomtype_id,group_detail_room.group_detail_room_price as group_detail_room_price FROM reservation_session,roomtype,room,group_detail,group_detail_room WHERE group_detail_room.group_detail_id = group_detail.group_detail_id AND group_detail_room.roomtype_id = roomtype.roomtype_id AND room.roomtype_id=group_detail_room.roomtype_id AND room.room_id=reservation_session.room_id AND group_detail.group_detail_id = '".$gValue."' AND reservation_session.reservation_detail_id = '$rID' GROUP BY roomtype.roomtype_id ORDER BY roomtype.roomtype_name");

$sQuery = mysql_query("SELECT group_detail_name FROM group_detail WHERE group_detail_id = '".$gValue."'");
$sRow = mysql_fetch_array($sQuery);
?>
<!-- แสดงรายการ Walk-in -->
<h3>บริษัท <?php echo $sRow['group_detail_name'];?></h3>
<table class="list">
<thead>
  <tr>
    <td class="center">ลำดับ</td>
    <td class="center">รายการ</td>
    <td class="center">จำนวน</td>
    <td class="center">ราคา/หน่วย</td>
    <td class="center">รวม</td>
  </tr>
</thead>
<?php 
$num=0;
while($rRow = mysql_fetch_array($rQuery)){
	$num++;
?>
  <tr>
    <td class="center"><?php echo $num;?></td>
    <td class="pLeft">
    <?php echo $rRow['roomtype_name']." ";
    	$RmQuery = mysql_query("SELECT room.room_name as room_name FROM room,reservation_session,roomtype WHERE room.roomtype_id=roomtype.roomtype_id AND room.room_id = reservation_session.room_id AND roomtype.roomtype_id = '".$rRow['roomtype']."' AND reservation_session.reservation_detail_id = '$rID' GROUP BY room.room_id");
    	while($RmRow = mysql_fetch_array($RmQuery)){
    		$room_name .= ", ".$RmRow['room_name'];
    	}
    		echo "(".substr($room_name, 2).")";
		$room_name = "";
    ?></td>
    <td class="pRight"><?php echo $rRow['roomtype_id'];?></td>
    <td class="pRight"><?php echo bath_format($rRow['group_detail_room_price']);?></td>
    <td class="pRight"><?php echo bath_format($rRow['roomtype_id']*$rRow['group_detail_room_price']);?></td>
  </tr>
<?php 
	$strtal = $strtal+($rRow['roomtype_id']*$rRow['group_detail_room_price']);
}
?>
<?php if($tABF!=""){
	$tABFQuery = mysql_query("SELECT more_information_price FROM more_information WHERE more_information_id = '1'");
	$tABFRow = mysql_fetch_array($tABFQuery);
	$NumtABF = 1;
?>
  <tr>
    <td class="center"><?php echo $num+$NumtABF;?></td>
    <td class="pLeft"><?php echo "รวมอาหารเช้า";?></td>
    <td class="pRight"><?php echo $tABF;?></td>
    <td class="pRight"><?php echo bath_format($tABFRow['more_information_price']);?></td>
    <td class="pRight"><?php $tABFTotal = $tABF*$tABFRow['more_information_price']; echo bath_format($tABFTotal);?></td>
  </tr>
<?php } ?>
<?php if($ExtraAbf!=""){
	$ExtraAbfQuery = mysql_query("SELECT more_information_price FROM more_information WHERE more_information_id = '2'");
	$ExtraAbfRow = mysql_fetch_array($ExtraAbfQuery);
	$NumExtraAbf = 1;
?>
  <tr>
    <td class="center"><?php echo $num+$NumExtraAbf+$NumtABF;?></td>
    <td class="pLeft"><?php echo "Extra Bed + ABF";?></td>
    <td class="pRight"><?php echo $ExtraAbf;?></td>
    <td class="pRight"><?php echo bath_format($ExtraAbfRow['more_information_price']);?></td>
    <td class="pRight"><?php $ExtraAbfTotal = $ExtraAbf*$ExtraAbfRow['more_information_price']; echo bath_format($ExtraAbfTotal);?></td>
  </tr>
<?php } ?>
<?php if($Extra!=""){
	$ExtraQuery = mysql_query("SELECT more_information_price FROM more_information WHERE more_information_id = '3'");
	$ExtraRow = mysql_fetch_array($ExtraQuery);
	$NumExtra = 1;
?>
  <tr>
    <td class="center"><?php echo $num+$NumExtraAbf+$NumtABF+$NumExtra;?></td>
    <td class="pLeft"><?php echo "Extra Bed";?></td>
    <td class="pRight"><?php echo $Extra;?></td>
    <td class="pRight"><?php echo bath_format($ExtraRow['more_information_price']);?></td>
    <td class="pRight"><?php $ExtraTotal = $Extra*$ExtraRow['more_information_price']; echo bath_format($ExtraTotal);?></td>
  </tr>
<?php } ?>
<?php if($AbfA!=""){
	$AbfAQuery = mysql_query("SELECT more_information_price FROM more_information WHERE more_information_id = '4'");
	$AbfARow = mysql_fetch_array($AbfAQuery);
	$NumAbfA = 1;
?>
  <tr>
    <td class="center"><?php echo $num+$NumExtraAbf+$NumtABF+$NumExtra+$NumAbfA;?></td>
    <td class="pLeft"><?php echo "ABF (ผู้ใหญ่)";?></td>
    <td class="pRight"><?php echo $AbfA;?></td>
    <td class="pRight"><?php echo bath_format($AbfARow['more_information_price']);?></td>
    <td class="pRight"><?php $AbfATotal = $AbfA*$AbfARow['more_information_price']; echo bath_format($AbfATotal);?></td>
  </tr>
<?php } ?>
<?php if($AbfC!=""){
	$AbfCQuery = mysql_query("SELECT more_information_price FROM more_information WHERE more_information_id = '5'");
	$AbfCRow = mysql_fetch_array($AbfCQuery);
	$NumAbfC = 1;
?>
  <tr>
    <td class="center"><?php echo $num+$NumExtraAbf+$NumtABF+$NumExtra+$NumAbfA+$NumAbfC;?></td>
    <td class="pLeft"><?php echo "ABF (เด็ก)";?></td>
    <td class="pRight"><?php echo $AbfC;?></td>
    <td class="pRight"><?php echo bath_format($AbfCRow['more_information_price']);?></td>
    <td class="pRight"><?php $AbfCTotal = $AbfC*$AbfCRow['more_information_price']; echo bath_format($AbfCTotal);?></td>
  </tr>
<?php } ?>
<?php if($AddA!=""){
	$AddAQuery = mysql_query("SELECT more_information_price FROM more_information WHERE more_information_id = '6'");
	$AddARow = mysql_fetch_array($AddAQuery);
	$NumAddA = 1;
?>
  <tr>
    <td class="center"><?php echo $num+$NumExtraAbf+$NumtABF+$NumExtra+$NumAbfA+$NumAbfC+$NumAddA;?></td>
    <td class="pLeft"><?php echo "พักเพิ่ม (ผู้ใหญ่)";?></td>
    <td class="pRight"><?php echo $AddA;?></td>
    <td class="pRight"><?php echo bath_format($AddARow['more_information_price']);?></td>
    <td class="pRight"><?php $AddATotal = $AddA*$AddARow['more_information_price']; echo bath_format($AddATotal);?></td>
  </tr>
<?php } ?>
<?php if($AddC!=""){
	$AddCQuery = mysql_query("SELECT more_information_price FROM more_information WHERE more_information_id = '7'");
	$AddCRow = mysql_fetch_array($AddCQuery);
	$NumAddC = 1;
?>
  <tr>
    <td class="center"><?php echo $num+$NumExtraAbf+$NumtABF+$NumExtra+$NumAbfA+$NumAbfC+$NumAddC+$NumAddA;?></td>
    <td class="pLeft"><?php echo "พักเพิ่ม (เด็ก)";?></td>
    <td class="pRight"><?php echo $AddC;?></td>
    <td class="pRight"><?php echo bath_format($AddCRow['more_information_price']);?></td>
    <td class="pRight"><?php $AddCTotal = $AddC*$AddCRow['more_information_price']; echo bath_format($AddCTotal);?></td>
  </tr>
<?php } ?>
  <tr>
	<td colspan="4" class="center"><b>รวมเงิน</b></td>
	<td class="pRight"><b><?php $strtalAll = $strtal+$tABFTotal+$ExtraAbfTotal+$ExtraTotal+$AbfATotal+$AbfCTotal+$AddATotal+$AddCTotal; echo bath_format($strtalAll);?></b></td>
  </tr>
</table>